import time


class TimeFunc:

    def __init__(self, func):
        self.func = func
        self._start = None
        self._end = None

    @staticmethod
    def __now():
        return time.time()

    def __enter__(self):
        self._start = self.__now()
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self._end = self.__now()
        print('exit f: %s time: %0.5f' % (self.func.__name__, (self._end - self._start)))

    def __call__(self, *args, **kwargs):
        self._start = self.__now()
        res = self.func(*args, **kwargs)
        self._end = self.__now()
        print('call f: %s time: %0.5f' % (self.func.__name__, (self._end - self._start)))
        return res


def jc(n):
    if n == 0 or n == 1:
        return 1
    else:
        return n * jc(n - 1)


def t(n):
    s = 0
    for i in range(10*n):
        s += jc(n)


with TimeFunc(t) as t:
    t(500)
    time.sleep(2)
    print('aaa')
